/* 
 * File:   Vector2DTest.cpp
 * Author: max
 *
 * Created on Nov 30, 2012, 11:26:29 AM
 */

#include <stdlib.h>
#include <iostream>
#include <math.h>
#include "Vector2D.h"

using namespace TP::Matematica;
/*
 * Simple C++ Test Suite
 */

void test1() {
    std::cout << "Vector2DTest test 1" << std::endl;
    Vector2D vector (10.0, 0.0);
    
    Vector2D direccion = vector.direccion();

    if (!(vector.direccion().X() == 1 && vector.direccion().Y() == 0))
        std::cout << "%TEST_FAILED% time=0 testname=test1 (Vector2DTest) message=la direccion del vector (10,0) difiere de (1,0)" << std::endl;
        
}

void test2() {
    std::cout << "Vector2DTest test 2" << std::endl;
    
    Vector2D *vectorA = new Vector2D (10.0, 5.0);
    Vector2D *vectorB = new Vector2D();
    vectorB->deElementoXML(vectorA->aElementoXML());
    
    if (!(vectorB->X() == 10.0 && vectorB->Y() == 5.0))
        std::cout << "%TEST_FAILED% time=0 testname=test2 (Vector2DTest) message=No serializa correctamente." << std::endl;
}

void test3(){
    std::cout << "Vector2DTest test 3" << std::endl;
    
    Vector2D *vectorA, *vectorB;
    vectorA = new Vector2D(1.0, 1.0);
    vectorB = new Vector2D();
    
    *vectorB = *vectorA * 10.0;
    
    if (!(vectorB->X() == 10.0 && vectorB->Y() == 10.0))
        std::cout << "%TEST_FAILED% time=0 testname=test3 (Vector2DTest) message=El productor por escalar no funciona correctamente." << std::endl;
}

void test4(){
    std::cout << "Vector2DTest test 4" << std::endl;
    
    Vector2D *vectorA, *vectorB, *vectorC;
    vectorA = new Vector2D(1.0, 1.0);
    vectorB = new Vector2D(1.0, 1.0);
    vectorC = new Vector2D();
    
    *vectorC = *vectorA + *vectorB;
    
    if (!(vectorC->X() == 2.0 && vectorC->Y() == 2.0))
        std::cout << "%TEST_FAILED% time=0 testname=test4 (Vector2DTest) message=La suma no funciona correctamente." << std::endl;

    *vectorC = *vectorA - *vectorB;
    
    if (!(vectorC->X() == 0.0 && vectorC->Y() == 0.0))
        std::cout << "%TEST_FAILED% time=0 testname=test4 (Vector2DTest) message=La resta no funciona correctamente." << std::endl;
}

void test5 (){
    std::cout << "Vector2DTest test 5" << std::endl;
    
    Vector2D *posA = new Vector2D (10.0, 10.0);
    Vector2D *posB = new Vector2D (10.0, 0.0);
    Vector2D aux
           , dir;
    
    aux = *posB - *posA;
    dir = aux.direccion();
    
    if (!(dir.X() == 0.0 && dir.Y() == -1.0))
        std::cout << "%TEST_FAILED% time=0 testname=test4 (Vector2DTest) message=La operacion (B-A).direccion no arroja el resultado esperado." << std::endl;
}

void test6 (){
    
    std::cout << "Vector2DTest test 6" << std::endl;
    
    Vector2D dir (1.0, 1.0)
           , aux (0.0, 0.0);
    
    aux.X(cos (dir.angulo() * 0.8));
    aux.Y(sin (dir.angulo() * 0.8));
    cout << endl << dir.aXML() << endl;
    cout << endl << aux.aXML() << endl;
    
    aux.X(cos (dir.angulo() * 0.6));
    aux.Y(sin (dir.angulo() * 0.6));
    cout << endl << dir.aXML() << endl;
    cout << endl << aux.aXML() << endl;
    
}

void test7()
{
    std::cout << "Vector2DTest test 7" << std::endl;
    
    Vector2D vector (1.0, 1.0);

    cout << endl << vector.aXML() << endl;
    cout << endl << "Angulo: " << vector.angulo() << endl;
}

int main(int argc, char** argv) {
    std::cout << "%SUITE_STARTING% Vector2DTest" << std::endl;
    std::cout << "%SUITE_STARTED%" << std::endl;

    std::cout << "%TEST_STARTED% test1 (Vector2DTest)" << std::endl;
    test1();
    std::cout << "%TEST_FINISHED% time=0 test1 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test2 (Vector2DTest)\n" << std::endl;
    test2();
    std::cout << "%TEST_FINISHED% time=0 test2 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test3 (Vector2DTest)\n" << std::endl;
    test3();
    std::cout << "%TEST_FINISHED% time=0 test3 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test4 (Vector2DTest)\n" << std::endl;
    test4();
    std::cout << "%TEST_FINISHED% time=0 test4 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test5 (Vector2DTest)\n" << std::endl;
    test5();
    std::cout << "%TEST_FINISHED% time=0 test5 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test6 (Vector2DTest)\n" << std::endl;
    test6();
    std::cout << "%TEST_FINISHED% time=0 test6 (Vector2DTest)" << std::endl;

    std::cout << "%TEST_STARTED% test7 (Vector2DTest)\n" << std::endl;
    test7();
    std::cout << "%TEST_FINISHED% time=0 test7 (Vector2DTest)" << std::endl;

    std::cout << "%SUITE_FINISHED% time=0" << std::endl;

    return (EXIT_SUCCESS);
}

